function chooseFile(options)
{
	var filename = null;
	var notifier = new EventNotifier();
    var defaults =
    {
        dir : getCurrentDir(),
        title : 'Select file',
        selectButtonText : 'Save',
        manual: false
    };

	// set default values
    options = $.extend(defaults, options);	
	
	// get files
	var files = enumerateDirectory(options.dir, options.test);
	
	// prepare dialog html
	var html = '<div class="dialog filechooser" id="dialog" title="' + options.title + '">';
	if (options.manual)
		html += 'File name: <input type="text" name="val" id="val" /><br />';
	else
		html += '<input type="hidden" name="val" id="val" />';
	html += '<ul class="options">';
	for (var i = 0; i < files.length; ++i)
		html += '<li><a href="#">' + files[i] + '</a></li>';
	html += '</ul>';
	html += '</div>';

	
	// callback to handle dialog closing
	var cb_close = function()
	{
		var d = $('#dialog');
		filename = null;
		if (d) 
		{
			if (d.attr('_submitted'))
				filename = d.find('#val').attr('value');
			d.dialog('destroy').remove();
		}
		notifier();
	}
	// buttons callbacks
	var cb_save = function(dialog) 
	{
		if (!$('#dialog #val').attr('value')) 
			return true; 
		$('#dialog').attr('_submitted', 'true'); 
		$('#dialog').dialog('close'); 
		return false;
	}
	var cb_cancel = function(dialog) 
	{
		$('#dialog a').removeClass('selected');
		$('#dialog #val').attr('value', '');
		$('#dialog').dialog('close');
		return false;
	}
	
	var buttons = {
		'Cancel': cb_cancel
	};
	buttons[options.selectButtonText] = cb_save;
	
	// create dialog
	$(html).dialog({modal: true, close: cb_close, buttons: buttons, width: 400, height: 400, autoOpen: false});
	// set anchors clicks  
	$('#dialog ul li a').click( function(){
		$('#dialog #val').attr('value', $(this).text());
		$('#dialog a').removeClass('selected');
		$(this).addClass('selected');
		return false;
	});
	// show dialog
	$('#dialog').dialog('open');
	notifier.wait->();
	return filename;
}


function getConfirmation(options)
{
	var answer = null;
	var notifier = new EventNotifier();
    var defaults =
    {
        title : 'Your changes will be lost',
		message : 'You are about to loose your changes.<br />Would you like to Save them?',
        yesButtonText : 'Yes',
		noButtonText : 'No',
		cancelButtonText : 'Cancel',
    };

	// set default values
    options = $.extend(defaults, options);	
	
	// prepare dialog html
	var html = '<div class="dialog" id="dialog" title="' + options.title + '">';
	html += '<p>' + options.message + '</p';
	html += '</div>';

	
	// callback to handle dialog closing
	var cb_close = function()
	{
		var d = $('#dialog');
		if (d) 
			d.dialog('destroy').remove();
		notifier();
	}
	// buttons callbacks
	var cb_button = function(ans) 
	{
		answer = ans; 
		$('#dialog').dialog('close');
		return false;
	}
	
	var buttons = {};
	buttons[options.cancelButtonText] = function() {cb_button(null)};
	buttons[options.noButtonText] = function() {cb_button(false)};
	buttons[options.yesButtonText] = function() {cb_button(true)};	
	
	// create dialog
	$(html).dialog({modal: true, close: cb_close, buttons: buttons, width: 400, height: 200});
	notifier.wait->();
	return answer;
}